package com.mdc.mansion.api.web.modules.basedata;


import com.alibaba.fastjson.JSONArray;
import com.mdc.mansion.api.web.common.web.BaseController;
import com.mdc.mansion.common.response.Result;
import com.mdc.mansion.common.response.ResultCode;
import com.mdc.mansion.core.modules.basedata.AppVersionService;
import com.mdc.mansion.core.modules.basedata.dto.AppConfigDTO;
import com.mdc.mansion.core.modules.system.SysDictService;
import com.mdc.mansion.dataaccess.modules.basedata.entity.AppVersion;
import com.mdc.mansion.dataaccess.modules.system.entity.Dict;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping(value = "${adminPath}/app")
public class AppConfigController extends BaseController {
    @Autowired
    private SysDictService sysDictService;
    @Autowired
    private AppVersionService appVersionService;

    @RequestMapping("config")
    public Result config(){
        Result result=new Result(ResultCode.COMMON_SUCCESS);
        Dict dict = new Dict();
        dict.setType(AppConfigDTO.appConfigType);
        List<Dict> list = sysDictService.findList(dict);
        if(CollectionUtils.isNotEmpty(list)){
            result.setProperty("appUrlConfig", JSONArray.parseArray(list.get(0).getValue()));}
        return result;
    }

    @RequestMapping("version")
    public Result version(String data){
        Result result=new Result(ResultCode.COMMON_SUCCESS);
        AppVersion appVersion=appVersionService.getVersionInfo(data);
        if(appVersion!=null){
            result.setProperty("appVersion",appVersion);}
        return result;
    }
}
